package com.itqf.config;

import com.itqf.condition.LinuxCondition;
import com.itqf.condition.WindowCondition;
import com.itqf.pojo.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * projectName: springframeworkgp8
 *
 * @author: 赵伟风
 * time: 2021/8/3 11:06
 * description:
 *    根据系统不同  Windows username = root password = root  url = jdbc:mysql:///gp8  driver = com.mysql.jdbc.Driver
 *                 Linux   username = admin password = 123  url = jdbc:mysql:///pro  driver = com.mysql.jdbc.Driver
 *
 *    @Conditional()
 *       情况1: 配置类上! 作用的范围当前类,如果conditional条件满足,当前配置类的所有bean被创建并放入ioc容器!
 *                                      如果conditional条件不满足,当前配置类的所有bean都不被创建并放入ioc容器!
 *       情况2: 配置类的方法上! 作用范围就是当前方法
 */
@Conditional({LinuxCondition.class, WindowCondition.class})
@Configuration
public class DataSourceConfig {


    /**
     * 当系统是window使用下面
     * @return
     */
    //@Conditional(WindowCondition.class)
    @Bean
    public DataSource createWindow(){

        DataSource dataSource = new DataSource();
        dataSource.setUsername("root");
        dataSource.setPassword("root");
        dataSource.setUrl("jdbc:mysql:///gp8");
        dataSource.setDriver("com.mysql.jdbc.Driver");

        return dataSource;
    }

    /**
     * 当系统是linux使用下面的实体
     * @return
     */

    @Bean
    public DataSource createLinux(){

        DataSource dataSource = new DataSource();
        dataSource.setUsername("admin");
        dataSource.setPassword("123456");
        dataSource.setUrl("jdbc:mysql:///pro");
        dataSource.setDriver("com.mysql.jdbc.Driver");

        return dataSource;
    }

}
